<!--
 * @Date: 2021-04-02 09:02:38
 * @LastEditors: Lzx
 * @FilePath: /web-vue/src/components/Logout.vue
 * @Desc: 
-->
<template></template>

<script>
import { mapState, mapMutations } from "vuex";

export default {
  data() {
    return {};
  },

  computed: {
    ...mapState(["userSession"]),
  },

  methods: {
    ...mapMutations({
      resetState: "resetState",
    }),

    // 退出登录
    logout() {
      // 注销请求
      this.$api
        .userLogout()
        .then((res) => {
          this.$message({
            message: res.data.message,
            type: "success",
            center: true,
            duration: 1680,
          });
        })
        .catch(function (err) {
          console.log(`【退出登录】接口发生错误:${err}`);
        });

      // 重置状态
      this.resetState();
      // 路由到登录页
      this.$router.go(0);
    },
  },
};
</script>

<style lang="scss" scoped></style>
